/***********************************************
/gen auto by zuitools
***********************************************/
#include "videoActivity.h"

/*TAG:GlobalVariable全局变量*/
static ZKButton* msys_backPtr;
static ZKWindow* msound_WindowPtr;
static ZKWindow* mcontrol_windowPtr;
static ZKSeekBar* msound_progressPtr;
static ZKButton* msoundPtr;
static ZKButton* mzoomPtr;
static ZKButton* mnextPtr;
static ZKButton* mprevPtr;
static ZKButton* mplay_pausePtr;
static ZKSeekBar* mprogressPtr;
static ZKVideoView* mvideoplayerPtr;

/*register activity*/
REGISTER_ACTIVITY(videoActivity);

typedef struct {
	int id; // 定时器ID ， 不能重复
	int time; // 定时器  时间间隔  单位 毫秒
}S_ACTIVITY_TIMEER;

#include "logic/videoLogic.cc"

/***********/
typedef struct {
    int id;
    const char *pApp;
} SAppInfo;

/**
 *点击跳转window
 */
static SAppInfo sAppInfoTab[] = {
//  { ID_MAIN_TEXT, "TextViewActivity" },
};

/***************/
typedef bool (*ButtonCallback)(ZKButton *pButton);
/**
 * button onclick表
 */
typedef struct {
    int id;
    ButtonCallback callback;
}S_ButtonCallback;

/*TAG:ButtonCallbackTab按键映射表*/
static S_ButtonCallback sButtonCallbackTab[] = {
    ID_VIDEO_sys_back, onButtonClick_sys_back,
    ID_VIDEO_sound, onButtonClick_sound,
    ID_VIDEO_zoom, onButtonClick_zoom,
    ID_VIDEO_next, onButtonClick_next,
    ID_VIDEO_prev, onButtonClick_prev,
    ID_VIDEO_play_pause, onButtonClick_play_pause,
};
/***************/


typedef void (*SeekBarCallback)(ZKSeekBar *pSeekBar, int progress);
typedef void (*SeekBarStartTrackingTouchCallback)(ZKSeekBar *pSeekBar);
typedef void (*SeekBarStopTrackingTouchCallback)(ZKSeekBar *pSeekBar);
typedef struct {
    int id;
    SeekBarCallback callback;
    SeekBarStartTrackingTouchCallback startTrackingTouchCB;
    SeekBarStopTrackingTouchCallback stopTrackingTouchCB;
}S_ZKSeekBarCallback;
/*TAG:SeekBarCallbackTab*/
static S_ZKSeekBarCallback SZKSeekBarCallbackTab[] = {
    ID_VIDEO_sound_progress, onProgressChanged_sound_progress, onProgressStartTrackingTouch_sound_progress, onProgressStopTrackingTouch_sound_progress,
    ID_VIDEO_progress, onProgressChanged_progress, onProgressStartTrackingTouch_progress, onProgressStopTrackingTouch_progress,
};


typedef int (*ListViewGetItemCountCallback)(const ZKListView *pListView);
typedef void (*ListViewobtainListItemDataCallback)(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index);
typedef void (*ListViewonItemClickCallback)(ZKListView *pListView, int index, int id);
typedef struct {
    int id;
    ListViewGetItemCountCallback getListItemCountCallback;
    ListViewobtainListItemDataCallback obtainListItemDataCallback;
    ListViewonItemClickCallback onItemClickCallback;
}S_ListViewFunctionsCallback;
/*TAG:ListViewFunctionsCallback*/
static S_ListViewFunctionsCallback SListViewFunctionsCallbackTab[] = {
};


typedef void (*SlideWindowItemClickCallback)(ZKSlideWindow *pSlideWindow, int index);
typedef struct {
    int id;
    SlideWindowItemClickCallback onSlideItemClickCallback;
}S_SlideWindowItemClickCallback;
/*TAG:SlideWindowFunctionsCallbackTab*/
static S_SlideWindowItemClickCallback SSlideWindowItemClickCallbackTab[] = {
};


typedef void (*EditTextInputCallback)(const std::string &text);
typedef struct {
    int id;
    EditTextInputCallback onEditTextChangedCallback;
}S_EditTextInputCallback;
/*TAG:EditTextInputCallback*/
static S_EditTextInputCallback SEditTextInputCallbackTab[] = {
};

videoActivity::videoActivity() {
	//todo add init code here
}

videoActivity::~videoActivity() {
	//todo add init file here
    // 退出应用时需要反注册
    EASYUICONTEXT->unregisterGlobalTouchListener(this);
    onUI_quit();
    unregisterProtocolDataUpdateListener(onProtocolDataUpdate);
}

const char* videoActivity::getAppName() const{
	return "video.ftu";
}

//TAG:onCreate
void videoActivity::onCreate() {
	Activity::onCreate();
    msys_backPtr = (ZKButton*)findControlByID(ID_VIDEO_sys_back);
	msound_WindowPtr = (ZKWindow*)findControlByID(ID_VIDEO_sound_Window);
	mcontrol_windowPtr = (ZKWindow*)findControlByID(ID_VIDEO_control_window);
    msound_progressPtr = (ZKSeekBar*)findControlByID(ID_VIDEO_sound_progress);if(msound_progressPtr!= NULL){msound_progressPtr->setSeekBarChangeListener(this);}
    msoundPtr = (ZKButton*)findControlByID(ID_VIDEO_sound);
    mzoomPtr = (ZKButton*)findControlByID(ID_VIDEO_zoom);
    mnextPtr = (ZKButton*)findControlByID(ID_VIDEO_next);
    mprevPtr = (ZKButton*)findControlByID(ID_VIDEO_prev);
    mplay_pausePtr = (ZKButton*)findControlByID(ID_VIDEO_play_pause);
    mvideoplayerPtr = (ZKVideoView*)findControlByID(ID_VIDEO_videoplayer);
    mprogressPtr = (ZKSeekBar*)findControlByID(ID_VIDEO_progress);if(mprogressPtr!= NULL){mprogressPtr->setSeekBarChangeListener(this);}
    if(mvideoplayerPtr){
    	mvideoplayerPtr->setClickListener(this);
    }
	onUI_init();
    registerProtocolDataUpdateListener(onProtocolDataUpdate);

    rigesterActivityTimer();
}

void videoActivity::onClick(ZKBase *pBase) {
    int buttonTablen = sizeof(sButtonCallbackTab) / sizeof(S_ButtonCallback);
    for (int i = 0; i < buttonTablen; ++i) {
        if (sButtonCallbackTab[i].id == pBase->getID()) {
            sButtonCallbackTab[i].callback((ZKButton*)pBase);
            break;
        }
    }

    int len = sizeof(sAppInfoTab) / sizeof(sAppInfoTab[0]);
    for (int i = 0; i < len; ++i) {
        if (sAppInfoTab[i].id == pBase->getID()) {
            EASYUICONTEXT->openActivity(sAppInfoTab[i].pApp);
            return;
        }
    }

	Activity::onClick(pBase);
}

void videoActivity::onResume() {
	Activity::onResume();
}

void videoActivity::onPause() {
	Activity::onPause();
}

void videoActivity::onIntent(const Intent *intentPtr) {
	Activity::onIntent(intentPtr);
}

bool videoActivity::onTimer(int id) {
	return onUI_Timer(id);
}

void videoActivity::onProgressChanged(ZKSeekBar *pSeekBar, int progress){
    int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
    for (int i = 0; i < seekBarTablen; ++i) {
        if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
            SZKSeekBarCallbackTab[i].callback(pSeekBar, progress);
            break;
        }
    }
}

void videoActivity::onStartTrackingTouch(ZKSeekBar *pSeekBar) {
	int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
	for (int i = 0; i < seekBarTablen; ++i) {
		if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
			SZKSeekBarCallbackTab[i].startTrackingTouchCB(pSeekBar);
			break;
		}
	}
}

void videoActivity::onStopTrackingTouch(ZKSeekBar *pSeekBar) {
	int seekBarTablen = sizeof(SZKSeekBarCallbackTab) / sizeof(S_ZKSeekBarCallback);
	for (int i = 0; i < seekBarTablen; ++i) {
		if (SZKSeekBarCallbackTab[i].id == pSeekBar->getID()) {
			SZKSeekBarCallbackTab[i].stopTrackingTouchCB(pSeekBar);
			break;
		}
	}
}

int videoActivity::getListItemCount(const ZKListView *pListView) const{
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            return SListViewFunctionsCallbackTab[i].getListItemCountCallback(pListView);
            break;
        }
    }
    return 0;
}

void videoActivity::obtainListItemData(ZKListView *pListView,ZKListView::ZKListItem *pListItem, int index){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].obtainListItemDataCallback(pListView, pListItem, index);
            break;
        }
    }
}

void videoActivity::onItemClick(ZKListView *pListView, int index, int id){
    int tablen = sizeof(SListViewFunctionsCallbackTab) / sizeof(S_ListViewFunctionsCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SListViewFunctionsCallbackTab[i].id == pListView->getID()) {
            SListViewFunctionsCallbackTab[i].onItemClickCallback(pListView, index, id);
            break;
        }
    }
}

void videoActivity::onSlideItemClick(ZKSlideWindow *pSlideWindow, int index) {
    int tablen = sizeof(SSlideWindowItemClickCallbackTab) / sizeof(S_SlideWindowItemClickCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SSlideWindowItemClickCallbackTab[i].id == pSlideWindow->getID()) {
            SSlideWindowItemClickCallbackTab[i].onSlideItemClickCallback(pSlideWindow, index);
            break;
        }
    }
}

bool videoActivity::onTouchEvent(const MotionEvent &ev) {
    return onvideoActivityTouchEvent(ev);
}

void videoActivity::onTextChanged(ZKTextView *pTextView, const std::string &text) {
    int tablen = sizeof(SEditTextInputCallbackTab) / sizeof(S_EditTextInputCallback);
    for (int i = 0; i < tablen; ++i) {
        if (SEditTextInputCallbackTab[i].id == pTextView->getID()) {
            SEditTextInputCallbackTab[i].onEditTextChangedCallback(text);
            break;
        }
    }
}

void videoActivity::rigesterActivityTimer() {
    int tablen = sizeof(REGISTER_ACTIVITY_TIMER_TAB) / sizeof(S_ACTIVITY_TIMEER);
    for (int i = 0; i < tablen; ++i) {
        S_ACTIVITY_TIMEER temp = REGISTER_ACTIVITY_TIMER_TAB[i];
        registerTimer(temp.id, temp.time);
    }
}
